package com.github.caijinglong

import com.github.caijinglong.handler.*

class SimpleStarter {

    companion object {
        @JvmStatic
        fun main(args: Array<String>) {
            if (args.isEmpty()) {
                println("zs/dz -g -c")
                println("zs/dz is type")
                println("-g is gold")
                println("-c is upgrade card")
                println("-t is upgrade card")
                println("-show showAll saved data")
                return
            }
            val s = args[0]
            val type =
                    when (s) {
                        "zs" -> SavedDataType.ZS
                        args[0] -> SavedDataType.DZ
                        else -> return
                    }

            if (args.contains("-show")) {
                val handler = InfoHandler()
                handler.bind(type.getGetter())
                handler.showAll()
            }

            if (args.contains("-t")) {
                val handler = PlayedTimeHandler()
                handler.bind(type.getGetter())
                handler.handleTime(10)
                handler.save(type.srcPath)
            }

            if (args.contains("-g")) {
                val goldHandler = GoldHandler()
                goldHandler.bind(type.getGetter())
                goldHandler.handlerGold(10000)
                goldHandler.save(type.srcPath)
            }

            if (args.contains("-h")) {
                val healthHandler = HealthHandler()
                healthHandler.bind(type.getGetter())
                healthHandler.maxHealth()
                healthHandler.save(type.srcPath)
            }

            if (args.contains("-c")) {
                val cardHandler = CardHandler()
                val getter = type.getGetter()
                cardHandler.bind(getter)
                cardHandler.removeDebuffCard()
                cardHandler.upgrade()
                cardHandler.save(type.srcPath)
                cardHandler.showAllCard()
            }

            relics(type, args)
        }

        fun relics(type: SavedDataType, args: Array<String>) {
            args.forEach {
                if (it.startsWith("-r")) {
                    val substring = it.substring(2)
                    val relicsHandler = RelicsHandler()
                    relicsHandler.bind(type.getGetter())
                    relicsHandler.addRelics(substring)
                    relicsHandler.save(type.srcPath)
                }
            }
        }
    }

}